
Partial Class WebForm_ManageBulletin_AddBulletin
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.fv.InsertItemTemplate = Me.fv.ItemTemplate
        Me.fv.EditItemTemplate = Me.fv.ItemTemplate
    End Sub

    Protected Sub fv_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles fv.DataBound
        Me.BindTopmost()
    End Sub

    Protected Sub fv_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles fv.ItemCommand
        If e.CommandName = "btnSave" Then
            If Me.SaveData() = True Then
                RaiseEvent Saved(Me, New EventArgs)
            End If
        ElseIf e.CommandName = "btnCancel" Then
            RaiseEvent Cancel(Me, New EventArgs)
        End If
    End Sub

End Class

Partial Class WebForm_ManageBulletin_AddBulletin
    Public Sub InitData()
        Me.fv.ChangeMode(FormViewMode.Insert)        
    End Sub

    Public Sub InitData(ByVal bulletinID As String)
        Me.fv.ChangeMode(FormViewMode.Edit)
        Me.BulletinID = bulletinID
        Me.BindData()
    End Sub
    Private Sub BindData()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Dim dt As Data.DataTable

        sql.AppendFormat("select b.*,CONVERT(char(10), issuedate, 120) issuedate_date ")
        sql.AppendFormat(" from FD_Bulletin b ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat("and b.BulletinID = '{0}' ", Me.BulletinID)

        dt = dat.GetData(sql)

        Me.fv.DataSource = dt
        Me.fv.DataBind()
    End Sub

    Private Sub BindTopmost()

        Dim ddlTopmost As DropDownList = TryCast(Me.fv.FindControl("ddlTopmost"), DropDownList)

        ddlTopmost.DataTextField = "Text"
        ddlTopmost.DataValueField = "Value"
        ddlTopmost.DataSource = MyObj.GetCodeMappingData("Bulletin", "Topmost")
        ddlTopmost.DataBind()
        ddlTopmost.Text = DataBinder.Eval(fv.DataItem, "Topmost")
    End Sub

    Private Function SaveData() As Boolean
        Dim sql As New MyStringBuilder
        Dim dat As New clsData
        Dim dtime As String
        dtime = DateTime.Now.ToString("yyyy/MM/dd 00:00:00")
        Dim cuser As String
        cuser = clsAuth.GetUserID()

        Using scope As New Transactions.TransactionScope
            If Me.fv.CurrentMode = FormViewMode.Insert Then
                sql.Length = 0
                sql.AppendFormat("insert FD_Bulletin (BulletinSubject,BulletinContent,Topmost,UserType,IssueDate,CreateDate,CreateBy) select ")
                sql.AppendFormat("'{0}' ", TryCast(fv.FindControl("txtBulletinSubject"), TextBox).Text)
                sql.AppendFormat(",'{0}' ", TryCast(fv.FindControl("txtBulletinContent"), TextBox).Text)
                sql.AppendFormat(",'{0}' ", TryCast(fv.FindControl("ddlTopmost"), DropDownList).Text)
                sql.AppendFormat(",'{0}' ", TryCast(fv.FindControl("ddlUserType"), DropDownList).Text)
                sql.AppendFormat(",'{0}' ", TryCast(fv.FindControl("txtIssueDate"), TextBox).Text)
                sql.AppendFormat(",'{0}' ", dtime)
                sql.AppendFormat(",'{0}' ", cuser)

                dat.AccData(sql)

                Me.BulletinSubject = TryCast(fv.FindControl("txtBulletinSubject"), TextBox).Text

            ElseIf Me.fv.CurrentMode = FormViewMode.Edit Then
                sql.Length = 0
                sql.AppendFormat("update FD_Bulletin set ")
                sql.AppendFormat(" BulletinSubject='{0}' ", TryCast(fv.FindControl("txtBulletinSubject"), TextBox).Text)
                sql.AppendFormat(",BulletinContent='{0}' ", TryCast(fv.FindControl("txtBulletinContent"), TextBox).Text)
                sql.AppendFormat(",Topmost='{0}' ", TryCast(fv.FindControl("ddlTopmost"), DropDownList).Text)
                sql.AppendFormat(",UserType='{0}' ", TryCast(fv.FindControl("ddlUserType"), DropDownList).Text)
                sql.AppendFormat(",IssueDate='{0}' ", TryCast(fv.FindControl("txtIssueDate"), TextBox).Text)
                sql.AppendFormat(",UpdateDate='{0}' ", dtime)
                sql.AppendFormat(",UpdateBy='{0}' ", cuser)
                sql.AppendFormat(" where BulletinID = '{0}' ", Me.BulletinID)
                dat.AccData(sql)
                Me.BulletinSubject = TryCast(fv.FindControl("txtBulletinSubject"), TextBox).Text
            End If

            scope.Complete()
        End Using

        Return True
    End Function

    Public Property BulletinID() As String
        Get
            Return ViewState("SelectedBulletinID")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedBulletinID") = value
        End Set
    End Property
    Public Property BulletinSubject() As String
        Get
            Return ViewState("SelectedBulletinSubject")
        End Get
        Set(ByVal value As String)
            ViewState("SelectedBulletinSubject") = value
        End Set
    End Property


    Public Event Saved(ByVal source As Object, ByVal e As EventArgs)
    Public Event Cancel(ByVal source As Object, ByVal e As EventArgs)
End Class
